<template>
  <div>
    <Drawer
      ref="DrawerRef"
      v-model="userInfoDrawer"
      title="用户信息"
      @close="DrawerClose"
      direction="rtl"
      :show-close="false"
    >
      <template #header>
        <h3>个人资料</h3>
        <el-button style="margin-right: 30px" type="success" round
          >绑定微信?</el-button
        >
      </template>
      <template #default>
        <!--:rules="rules"  -->
        <el-form
          :model="formData"
          ref="formDataRef"
          label-width="80px"
          @submit.prevent
        >
          <el-form-item label="用户名:" prop="nickName">
            <el-input
              clearable
              placeholder="提示信息"
              v-model.trim="formData.nickName"
              disabled
            ></el-input>
          </el-form-item>
          <!--textarea输入-->
          <el-form-item label="头像:" prop="avatar">
            <ImagePreview :src="formData.avatar" />
          </el-form-item>
          <el-form-item label="已用空间:" prop="useSpace">
            <el-input
              clearable
              placeholder="提示信息"
              v-model.trim="formData.useSpace"
              disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="总空间:" prop="totalSpace">
            <el-input
              clearable
              placeholder="提示信息"
              v-model.trim="formData.totalSpace"
              disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="上次登陆时间:" prop="lastLoginTime">
            <el-input
              clearable
              placeholder="提示信息"
              v-model.trim="formData.lastLoginTime"
              disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="创建时间:" prop="createTime">
            <!-- Image-Preview -->
            <el-input
              clearable
              placeholder="提示信息"
              v-model.trim="formData.createTime"
              disabled
            ></el-input>
          </el-form-item>
        </el-form>
      </template>
      <template #footer> </template>
    </Drawer>
  </div>
</template>

<script setup>
import {
  ref,
  reactive,
  getCurrentInstance,
  nextTick,
  onMounted,
  inject,
} from "vue";
import { ElMessage } from "element-plus";
import { useRoute, useRouter } from "vue-router";
const { proxy } = getCurrentInstance();
import { getUserInfo } from "@/api/userinfo";
// 路径参数
const route = useRoute();
//  路由
const router = useRouter();
// 注入userinfo (登录数据)
const userInfo = inject("userInfo");

const userInfoDrawer = ref(false);
// 抽屉ref
const DrawerRef = ref();
// 用户详细信息
const formData = ref({
  //   表单数据
});
// emit关闭事件
const emit = defineEmits(["update:userInfoDrawer"]);

const showUserInfo = () => {
  userInfoDrawer.value = true;
};

const DrawerClose = () => {
  // 恢复数据原始状态
  //   console.log("DrawerClose");
};

// 获取用户详细信息
const getUserInfoFun = async () => {
  await getUserInfo(userInfo.value.userId).then((res) => {
    formData.value = res.data;
  });
  console.log("用户详细信息:", formData.value);
};



onMounted(() => {
  // 获取用户详细信息
  getUserInfoFun();
  console.log("DrawerRef:", DrawerRef.value);
});

defineExpose({ showUserInfo,getUserInfoFun });
</script>

<style lang="scss" scoped></style>
